package com.xyh.flowershop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xyh.flowershop.context.WebContext;
import com.xyh.flowershop.domain.TipDict;
import com.xyh.flowershop.mapper.TipDictMapper;
import com.xyh.flowershop.service.TipDictService;
import com.xyh.flowershop.vo.req.tip.TipDictEditReqVo;
import com.xyh.flowershop.vo.resp.tipdict.TipDictRespPageVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author 小约翰可汗
 * @className TipDictServiceImpl
 * @createTime 2024/7/717:21
 */
@Service("tipDictService")
public class TipDictServiceImpl extends ServiceImpl<TipDictMapper,TipDict> implements TipDictService {
    @Override
    public Boolean addOrEditTipDict(TipDictEditReqVo vo) {
        TipDict tipDict = new TipDict();
        String curUserId = WebContext.get();
        BeanUtils.copyProperties(vo,tipDict);
        int row = 0;
        if(ObjectUtils.isEmpty(vo.getId())){
            tipDict.setUserId(curUserId);
            tipDict.setUpdateUserId(curUserId);
            row =baseMapper.insert(tipDict);
        }else{
            tipDict.setUpdateTime(new Date());
            tipDict.setUpdateUserId(curUserId);
            row = baseMapper.updateById(tipDict);
        }
        return row > 0;
    }

    @Override
    public List<TipDictRespPageVo> findTipDictList() {
        /*List<TipDictRespPageVo> parentTipDict = baseMapper.selectParentTipDict();
        parentTipDict.stream().forEach(item -> {
            List<TipDictRespPageVo> childTipDict = baseMapper.selectChildTipDict(item.getTipId());
            item.setChildren(childTipDict);
        });
        return parentTipDict;*/
        return baseMapper.selectTipDictList();
    }
}
